{% extends "master.html" %}
{% block subtitle %} - 店铺管理 - 创建店铺{% endblock %}

{% block extCSS %}
<style type="text/css">
    .atmtemplate{
        display : none;
    }
</style>
{% endblock %}
{% block extJS %}
<script language="JavaScript" type="text/javascript">
//<![CDATA[
    $(document).ready(function(){
        $("#provinceID").change(function(){
            provinceChange(this,'#cityID');
        });
    });
    
    function toSubmit(){
        var msg = [];
        clearMsg();
        $(".err").removeClass('err');
        
        if(!$("#shortName").val()){
            msg.push('请填写商店的简称！');
            $("#shortName").addClass('err');
        }
        
        if(!$("#name").val()){
            msg.push('请填写商店的全称！');
            $("#name").addClass('err');
        }
        
        if(!$("#accname").val()){
            msg.push('请填写商店的账户名称！');
            $("#accname").addClass('err');
        }
        
        if(!$("#accbankID").val()){
            msg.push('请填写商店的账户银行！');
            $("#accbankID").addClass('err');
        }
        
        if(!$("#acccode").val()){
            msg.push('请填写商店的账户号码！');
            $("#acccode").addClass('err');
        }
        
        if(!$("#acccurrencyID").val()){
            msg.push('请填写商店的账户货币！');
            $("#acccurrencyID").addClass('err');
        }
        
        if(!$("#accpaytypeID").val()){
            msg.push('请填写商店的支付方式！');
            $("#accpaytypeID").addClass('err');
        }
        
        if(!$("#accowner").val()){
            msg.push('请填写商店的账户拥有人！');
            $("#accowner").addClass('err');
        }
        
                
        if(msg.length > 0){
            alertError(msg);
            return false;
        }else{
            $("form").submit();
        }
        
    }
    
    function toCancel(){
         redirect_alert("{{MSG_LEAVE_WITHOUT_SAVING}}","{{url_for('.view')}}");
    }
//]]>
 </script>
{% endblock %}

{% block main %}
<div class="container">
    <div class="row">
        <ol class="breadcrumb">
          <li><a href="{{url_for('bpMas.view')}}">基础信息</a></li>
          <li><a href="{{url_for('bpShop.view')}}">店铺管理</a></li>
          <li class="active">创建店铺</li>
        </ol>
    </div>
    <div class="row">
        <div class="btn-toolbar pull-right">
            <div class="btn-group"><button type="button" class="btn btn-primary" onclick="toSubmit()">确认提交</button></div>
            <div class="btn-group"><button type="button" class="btn btn-inverse" onclick="toCancel()">取消</button></div>
        </div>
    </div>
    <div class="row">
        <form class="" method='POST' action="{{url_for('bpShop.view',action='add')}}"  enctype="multipart/form-data">
            <fieldset>
                <legend>店铺基本信息</legend>
                
                <div class="col-md-4">
                    {{ mymacros.render_required_field(form.shortName) }}
                    {{ mymacros.render_required_field(form.name) }}
                    <div class="control-group">
                        <label class="control-label"><label for="address">地址</label></label>
                        <div class="controls">
                            {{mymacros.select('provinceID',list=getMaster('Province'),value=None)}}
                            {{mymacros.select('cityID',list=[],value=None,blank_option=False)}}
                            <input name="address" id="address" value=""/>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    {{ mymacros.render_field(form.fund) }}
                    {{ mymacros.render_field(form.legalPerson) }}                    
                </div>                  
                <div class="col-md-4">
                    <div class="control-group">
                        <label class="control-label"><label for="shopType">店铺类型</label></label>
                        <div class="controls">
                            <select name="shopType" id="shopType">
                                {% for v,n in [((SHOP_TYPE_MAIN|string),'总店'),((SHOP_TYPE_BRANCH|string),'门店')] %}
                                    <option value="{{v}}">{{n}}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="saleType">销售方式</label></label>
                        <div class="controls">
                            <select name="saleType" id="saleType">
                                {% for v,n in [(SHOP_SALE_TYPE_SELF|string,'自营'),(SHOP_SALE_TYPE_JOIN|string,'加盟')] %}
                                    <option value="{{v}}">{{n}}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="remark">备注</label></label>
                        <div class="controls"><textarea name="remark" id="remark"></textarea></div>
                    </div>
                </div>                    
            </fieldset>
            
            <fieldset>
                <legend>店铺账户信息</legend>
                <div class="col-md-4">
                    <div class="control-group">
                        <label class="control-label"><label for="accname">账户名称<span style='color:red'>*</span></label></label>
                        <div class="controls"><input type="text" name="accname" id="accname"/></div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="accbankID">账户银行<span style='color:red'>*</span></label></label>
                        <div class="controls">
                              {{mymacros.select('accbankID',list=getMaster('Bank','name'),value=None)}}
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="control-group">
                        <label class="control-label"><label for="acccode">账户号码<span style='color:red'>*</span></label></label>
                        <div class="controls"><input type="text" value="" name="acccode" id="acccode"></div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="accowner">账户拥有人<span style='color:red'>*</span></label></label>
                        <div class="controls"><input type="text" value="" name="accowner" id="accowner"></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="control-group">
                        <label class="control-label"><label for="acccurrencyID">账户货币<span style='color:red'>*</span></label></label>
                        <div class="controls">
                            <select name="acccurrencyID" id="acccurrencyID">
                                {% for c in getMaster('Currency') %}
                                    {% if c.isDefault %}
                                        <option value="{{c.id}}" selected="selected">{{c}}</option>
                                    {% else %}
                                        <option value="{{c.id}}">{{c}}</option>
                                    {% endif %}
                                {% endfor %}
                            </select>
                        </div>
                    </div>                    
                    <div class="control-group">
                        <label class="control-label"><label for="accpaytypeID">支付方式<span style='color:red'>*</span></label></label>
                        <div class="controls">
                            <select name="accpaytypeID" id="accpaytypeID">
                                {% for p in getMaster('Paytype') %}
                                    {% if p.isDefault %}
                                        <option value="{{p.id}}" selected="selected">{{p}}</option>
                                    {% else %}
                                        <option value="{{p.id}}">{{p}}</option>
                                    {% endif %}
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    
                    <div class="control-group">
                        <label class="control-label"><label for="accamount">余额</label></label>
                        <div class="controls"><input type="text" value="0" name="accamount" id="accamount" class="num"></div>
                    </div>
                </div>                    
            </fieldset>  
                    
            
            <fieldset>
                <legend>店铺功能信息</legend>
                
                <div class="control-group">
                    <label class="control-label"><label for="">包含模块</label></label>
                    <div class="controls">
                        <label class="checkbox">
                          <input type="checkbox" name="canSale" value="0"> 销售产品模块
                        </label>
                        <label class="checkbox">
                          <input type="checkbox" name="canPurchase" value="0"> 采购产品模块
                        </label>
                        <label class="checkbox">
                          <input type="checkbox" name="canGetWarehouse" value="0"> 仓存模块
                        </label>
                        <label class="checkbox">
                          <input type="checkbox" name="canUpdateProduct" value="0"> 更新商品模块
                        </label>
                        <label class="checkbox">
                          <input type="checkbox" name="canUpdateOfficer" value="0"> 更新人员模块
                        </label>
                    </div>
                </div>
            </fieldset>
                
            <fieldset>
                <legend>附件</legend>
                <div class="control-group">
                  <label class="control-label" for="attachment"><button class="btn btn-default" onclick="return addAtm('atmtemplate','atmmk','#atmul')">添加附件</button></label>
                  <div class="controls">
                      <ul id="atmul">
                          <li><input type="file" name="atm_10"/></li>
                          <li class="atmtemplate"><input type="file" name="atm_x"/><button class="btn btn-default" onclick="delAtm(this,'atmmk')">-</button></li>
                      </ul>
                  </div>
                </div>
            </fieldset>        
        </form>
    </div>
    
   
</div>
{% endblock %}